import { UserTokenCookie } from '../utils/cookie'

export default function ({ route, next, store }) {
    const token = UserTokenCookie.getToken()
    const whiteArr = ['/login', '/reg']
    const hasRoles = store.getters.roles && store.getters.roles.length > 0

    if (token) {
        if (hasRoles) {

        } else {
            store.dispatch('users/getUserInfo', token)
        }
    } else {
        if (whiteArr.includes(route.path)) {
            // TODO
        } else {
            next({ path: '/login', redirect: true })
        }
    }
    // console.log(route)
}